package com.lyj.properties.encrypt.controller;

import org.jasypt.encryption.StringEncryptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class ApiController {

    @Autowired
    StringEncryptor encryptor;

    @Value("${newUsername}")
    private String username;

    @Value("${password}")
    private String password;

    /**
     * 解密
     * @author: liyajie
     * @date: 2022/1/12 10:27
     * @param
     * @return java.util.List<java.util.Map<java.lang.String,java.lang.String>>
     * @exception:
     * @update:
     * @updatePerson:
     **/
    @GetMapping("/getUsernameAndPassword")
    public Map<String,String> getUsernameAndPassword(){
        Map<String,String> map = new HashMap<String,String>();
        map.put("解密后username",username);
        map.put("解密后password",password);
        return map;
    }

    /**
     * 加密
     * @author: liyajie
     * @date: 2022/1/12 10:27
     * @param
     * @return java.util.Map<java.lang.String,java.lang.String>
     * @exception:
     * @update:
     * @updatePerson:
     **/
    @GetMapping("/setUsernameAndPassword")
    public Map<String,String> setUsernameAndPassword(String username, String password){
        Map<String,String> map = new HashMap<String,String>();
        map.put("加密后username",encryptor.encrypt(username));
        map.put("加密后password",encryptor.encrypt(password));
        return map;
    }



}
